#include "conjunction.h"
#include  <stdlib.h>
using cdnf::Conjunction;

//Conjunction::Conjunction(){}
bool Conjunction::getValue(bool* valuation){	
	if(this->terms.size()==0)
		return true;
	for (unsigned int i=0;i<terms.size();i++){
		bool value;
			if (terms[i] > 0)
				value = valuation[terms[i]];
			else
				value = (valuation[-terms[i]]) ? false : true;
			if (!value)
				return false;
	}
	return true;
}
bool Conjunction::getValue(Valuation& valuation){
	if(this->terms.size()==0)
		return true;
	for (unsigned int i=0;i<terms.size();i++){
		bool value;
			if (terms[i] > 0)
				value = valuation[terms[i]];
			else
				value = (valuation[-terms[i]]) ? false : true;
			if (!value)
				return false;
	}
	return true;
}
bool Conjunction::getValue(std::vector<int> values){
	if(values.size() < terms.size())
		return false;
	int i =0,j=0;
	while(i<values.size()&&j<terms.size()){
		while(abs(terms[j])>abs(values[i]))i++;
		if(terms[j]!=values[i])
			return false;
		i++;j++;
	}
	if(j== terms.size())return true;
	else return false;
}
std::vector<int>& Conjunction::getTerms(){
	return this->terms;
}
void Conjunction::setTerms(std::vector<int> terms){
	this->terms=terms;
}
void Conjunction::addTerm(int term){
	this->terms.push_back(term);
}
int Conjunction::getTerm(int index){
	return this->terms.at(index);
}
void Conjunction::setTerm(int index,int term){
	this->terms[index]=term;
}
bool Conjunction::isDegenerated(){
	return (this->terms.size()==0);
}
void Conjunction::setDegeneratedValue(bool degeneratedValue){
	this->degeneratedValue=degeneratedValue;
}
bool Conjunction::getDegeneratedValue(){
	return this->degeneratedValue;
}
